#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import random

'''
.net.gameroom.room
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
游戏房间
'''
class room:
    def __init__(self):
        self.rooms={}
    def makeRoomNo(self):
        '''
        Feature
            makeRoomNo(self)
        Description
            随机生成房间号1000-9999
        '''
        return random.randint(1000,9999)

    def join(self,roomno,user):
        '''
        Feature
            join(self,roomno,user)
        Description
            加入房间
        Args
            roomno
                type:int
                description:房号
            user
                type:WS_User
                description:用户
        '''
        if self.rooms[roomno]:
            self.rooms[roomno].append(user)
            return True
        else:
            return False

    def create(self,user):
        '''
        Feature
            create(self,user)
        Description
            建立一个房间
        Args
            user
                type:WS_User
                description：用户
        '''
        try:
            self.rooms[self.makeRoomNo()].append(user)
            return True
        except:
            return False